﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.OleDb;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

namespace skvote
{
    public partial class admin_question_modify : System.Web.UI.Page
    {
        private OleDbConnection connection = new conn().CreateConnection();
        protected void Page_Load(object sender, EventArgs e)
        {
            function.check();
            function.IsNumberOrEmpty(Request["id"]);
            function.IsNumberOrEmpty(Request["tid"]);
        }
        public string GetQuestion(string id)
        {
            string question = "";
            if (!string.IsNullOrEmpty(id))
            {
                try
                {
                    connection.Close();
                    connection.Open();
                    OleDbCommand cmd = new OleDbCommand("select * from xh_question where id=" + id.Trim(), connection);
                    OleDbDataReader dr = cmd.ExecuteReader();
                    while (dr.Read())
                    {
                        question = dr["question"].ToString();
                    }
                    dr.Close();
                    cmd.Dispose();
                }
                finally
                {
                    connection.Close();
                }
            }
            return question;
        }
        public string GetPs(string id)
        {
            string ps = "";
            if (!string.IsNullOrEmpty(id))
            {
                try
                {
                    connection.Close();
                    connection.Open();
                    OleDbCommand cmd = new OleDbCommand("select * from xh_question where id=" + id.Trim(), connection);
                    OleDbDataReader dr = cmd.ExecuteReader();
                    while (dr.Read())
                    {
                        ps = dr["ps"].ToString();
                    }
                    dr.Close();
                    cmd.Dispose();
                }
                finally
                {
                    connection.Close();
                }
            }
            return ps;
        }

        protected void submit_Click(object sender, EventArgs e)
        {
            /*function.IsNumberOrEmpty(Request["ttid"]);
            function.IsNumberOrEmpty(Request["question"]);
            function.IsNumberOrEmpty(Request["ps"]);
            function.IsNumberOrEmpty(Request["id"]);*/
            try
            {
                string sid = "";
                connection.Close();
                connection.Open();
                OleDbCommand cmd = new OleDbCommand("select * from xh_title where id=" + Request["ttid"].Trim(), connection);
                OleDbDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    sid = dr["sid"].ToString();
                }
                dr.Close();
                cmd.CommandText = "update xh_question set question=\"" + Request["question"].Trim() + "\",tid=" + Request["ttid"].Trim() + ",sid=" + sid.Trim() + ",ps=" + Request["ps"].Trim() + " where id=" + Request["id"];
                cmd.ExecuteNonQuery();
                cmd.CommandText = "select sum(ps) as ps from xh_question where tid=" + Request["ttid"];
                string vcount = cmd.ExecuteScalar().ToString();
                cmd.CommandText = "update xh_title set vcount=" + vcount + " where id=" + Request["ttid"];
                cmd.ExecuteNonQuery();
                cmd.Dispose();
            }
            finally
            {
                connection.Close();
            }
            function.successMsg("修改信息成功");
        }
    }
}
